package com.jxm.spring.security.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jxm.spring.security.bean.Menu;
import com.jxm.spring.security.bean.Role;
import com.jxm.spring.security.bean.User;
import com.jxm.spring.security.mapper.UserMapper;
import com.jxm.spring.security.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统用户 服务实现类
 * </p>
 *
 * @author jxm
 * @since 2021-05-16
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    @Override
    public User findUserByUserName(String username) {
//        return this.baseMapper.selectOne(
//                new QueryWrapper<SysUser>().lambda().eq(SysUser::getUsername, username).ne(SysUser::getStatus, "1"));
        return this.baseMapper.selectOne(new QueryWrapper<User>().eq("username",username).eq("enabled",1));
    }

    /**
     * 根据用户ID查询角色
     * @param userId 用户ID
     * @return
     */
    @Override
    public List<Role> findRoleByUserId(Long userId) {


        return this.baseMapper.findRoleByUserId(userId);

    }

    /**
     * 根据用户ID查询权限
     * @param userId 用户ID
     * @return
     */
    @Override
    public List<Menu> findAuthByUserId(Long userId) {
        return this.baseMapper.findAuthByUserId(userId);
    }
}
